﻿using IDAdmin.Common;
using IDAdmin.Lib.DataLayer;
using IDAdmin.Lib.UI;
using IDAdmin.Lib.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IDAdmin.Pages
{
    public partial class Ratio : BasePage
    {
        public Ratio()
            : base(Lib.AppFunctions.RATIO)
        {

        }

        protected override void Page_Load(object sender, EventArgs e)
        {
            if (!IsLogin())
            {
                RedirectToLogOn();
            }
            else if (!CheckRight())
            {
                RedirectToDeniedMessage();
            }
            dataPanel.Controls.Add(ShowResult());
        }

        private Table ShowResult()
        {
            Table table = new Table();
            table.CssClass = "table1";
            TableRow rowHeader = new TableRow();
            rowHeader.Cells.AddRange(
                new TableCell[]
                { 
                    UIHelpers.CreateTableCell("STT",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),
                    UIHelpers.CreateTableCell("Số Gosu",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"),   
                     UIHelpers.CreateTableCell("Tỉ lệ",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"), 
                      UIHelpers.CreateTableCell("Số phiếu điểm",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"), 
                      UIHelpers.CreateTableCell("Chi tiết",Unit.Percentage(5), HorizontalAlign.Center,"cellHeader"), 
                }
            );
            table.Rows.Add(rowHeader);

            try
            {
                List<RatioGosu> lData = new List<RatioGosu>();
                lData = WebDB_N.getListRationDb();
                string css;
                int stt = 0;
                try
                {
                    foreach (var item in lData)
                    {
                        stt++;
                        css = stt % 2 == 0 ? "cell1" : "cell2";
                        TableRow row = new TableRow();       
                        row.Cells.AddRange
                        (
                            new TableCell[]
                                    {
                                        UIHelpers.CreateTableCell(stt.ToString(),HorizontalAlign.Center,css),
                                        UIHelpers.CreateTableCell(item.gosu.ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),
                                        UIHelpers.CreateTableCell(item.ratio ,HorizontalAlign.Center,css),
                                        UIHelpers.CreateTableCell(item.phieudiem.ToString("N0", CultureInfo.InvariantCulture),HorizontalAlign.Center,css),    
                                        UIHelpers.CreateTableCell("<a href='RatioDetails.aspx?id="+item.id+"'>Sửa<a/>,<a href='RatioDetails.aspx'>Tạo mới<a/>",HorizontalAlign.Center,css)                                               
                                    }
                        );
                        table.Rows.Add(row);                       

                    }
                }
                catch (Exception ex)
                {

                }

            }
            catch (Exception ex)
            {

            }
            return table;
        }
    }
}